import { Component, inject } from '@angular/core';
import { SunshineNgZorroAntdModule } from '../../ng-zorro-module';
import { NZ_MODAL_DATA } from 'ng-zorro-antd/modal';
import { SunshineEmp } from '../emp.entity';
import { NzMessageService } from 'ng-zorro-antd/message';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { SunshineEmpConstant } from '../Constant';

@Component({
  selector: 'app-sunshine-emp-detail',
  standalone: true,
  imports: [SunshineNgZorroAntdModule],
  templateUrl: './sunshine-emp-detail.component.html',
  styleUrls: ['./sunshine-emp-detail.component.css']
})
export class SunshineEmpDetailComponent {
  // 获取传入的参数
  isDisable: boolean = inject(NZ_MODAL_DATA).isDisable;
  id: number = inject(NZ_MODAL_DATA).id;
  emp: SunshineEmp = inject(NZ_MODAL_DATA) == undefined || inject(NZ_MODAL_DATA) == null ? {
    empId: null, empName: null, gender: null, email: null
  } : inject(NZ_MODAL_DATA);
  http: HttpClient = inject(HttpClient);

  options = [
    { label: '男', value: '1' },
    { label: '女', value: '2' }
  ];

  autoTips: Record<string, Record<string, string>> = {
    'zh-cn': {
      required: '必填项'
    },
    en: {
      required: 'Input is required'
    },
    default: {
      email: '邮箱格式不正确/The input is not valid email'
    }
  };
  
  constructor() { }

  ngOnInit(): void {
    console.log("dataItem = ", this.emp)
    // console.log("id = ", this.id)
    // console.log("isDisable = ", this.isDisable)
  }
  saveEmp(reslv:any): Promise<any> {
    return new Promise(() => {
      console.log(this.emp);

      const httpOptions = {
        headers: new HttpHeaders({
          'Content-Type': 'application/json'
        })
      };
      console.log(httpOptions)
      return this.http.put(SunshineEmpConstant.path.insert, JSON.stringify(this.emp), httpOptions).subscribe(reslv, () => { });
      ;
    });
  }

  updateEmp(reslv: any): Promise<any> {
    return new Promise(() => {
      console.log(this.emp);

      const httpOptions = {
        headers: new HttpHeaders({
          'Content-Type': 'application/json'
        })
      };
      console.log(httpOptions)
      return this.http.put(SunshineEmpConstant.path.update+this.emp.empId, JSON.stringify(this.emp), httpOptions).subscribe(reslv, () => { });
      ;
    });
  }

}
